#include "singlelist.h"

SingleList::SingleList()
{
    this->head.next = NULL;
    this->currentNode = &(this->head);
}

SingleList::~SingleList()
{
    while(!isEmpty())
    {
        this->delTail();
    }
}

int * SingleList::addHead(int data)
{
    this->currentNode = &(this->head);
    ListNode * node = new ListNode();
    if(node == NULL)
        return NULL;

    node->data = data;
    node->next = this->head.next;
    this->head.next = node;
    return &(node->data);
}

int * SingleList::next()
{
    if(&(this->head) == this->currentNode)
    {
        this->currentNode = this->head.next;
    }
    else
    {
        this->currentNode = this->currentNode->next;
    }
    if(NULL == this->currentNode)
        return NULL;

    return &(currentNode->data);
}

void SingleList::reset()
{
    this->currentNode = &(this->head);
}
